package fr.afcepf.atod18.client.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import fr.afcepf.atod18.client.entity.Client;
import fr.afcepf.atod18.utilitaires.dao.IGenericDao;

@Service
@Transactional
public class ServiceClient implements IServiceClient {
	@Autowired
	IGenericDao<Client> daoClient;


	@Override
	public void ajouter(Client client) {
		daoClient.save(client);
	}
	@Override
	public Client mettreAJour(Client client) {
	    return daoClient.update(client);
	}
	@Override
	public Client rechercherParId(int id) {
		Client cl= daoClient.findOne(id);
		int i = cl.getAdresses().size();
	    return cl;
	}
	@Override
	public List<Client> rechercherTout() {
		return daoClient.findAll();
	}
	@Override
	public void supprimerParId(int id) {
	    daoClient.deleteById(id);
	}
	@Override
	public void supprimer(Client client) {
	    daoClient.delete(client);
	}
    @Override
	public void supprimerListe(List<Client> liste) {
		daoClient.deleteList(liste);
	}
    @Override
    public List<Client> rechercherParNom(String nomColonne, String libelle) {
        return daoClient.findByName(nomColonne, libelle);
    }

    public IGenericDao<Client> getDaoClient() {
		return daoClient;
	}
	public void setDaoClient(IGenericDao<Client> daoClient) {
		this.daoClient = daoClient;
	}
}
